package com.bwie.controller;

import com.bwie.pojo.TbType;
import com.bwie.service.TbTypeService;
import com.bwie.utils.R;
import com.github.tobato.fastdfs.service.FastFileStorageClient;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.codec.multipart.FilePart;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.naming.Name;

@RestController
@RequestMapping("/brand/type")
public class TypeController {

    @Autowired
    TbTypeService typeService;

    @Autowired
    FastFileStorageClient fastFileStorageClient;

    @ApiOperation("添加类型")
    @PostMapping("/addType")
    public R addType(@RequestBody TbType type){
        return typeService.addType(type);
    }

    @ApiOperation("获取树状表单")
    @GetMapping("/getTreeTable")
    public R getTreeTable(){

        return typeService.getTreeTable();
    }

    @DeleteMapping("/deleteType/{id}")
    public R deleteType(@PathVariable(name = "id")Integer id){
        return typeService.deleteType(id);
    }

    @ApiOperation("图片上传")
    @PostMapping("/uploadImage")
    public R uploadImage(@RequestPart(name ="file")MultipartFile file){
        return typeService.uploadImage(file);
    }

    @ApiOperation("添加类型")
    @PostMapping("/saveType")
    public R saveType(@RequestBody TbType type){
        return typeService.saveType(type);
    }

    @ApiOperation("修改类型")
    @PostMapping("/updateType")
    public R updateType(@RequestBody TbType type){
        return typeService.updateType(type);
    }

    @ApiOperation("修改类型显示状态")
    @PostMapping("/updateShow/{typeId}/{typeStatus}")
    public R updateStatus(@PathVariable(name = "typeId")Integer typeId,@PathVariable(name = "typeStatus")Integer typeStatus){
        return typeService.updateShow(typeId,typeStatus);
    }
}
